package com.buaa.airticketbookingsystem.Controller;

import com.buaa.airticketbookingsystem.Entity.FavouriteRecord;
import com.buaa.airticketbookingsystem.Service.FavouriteService;
import com.buaa.airticketbookingsystem.Service.TicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@CrossOrigin
@RestController
public class ColletionsCenterController {
    @Autowired
    private FavouriteService favouriteService;

    @PostMapping("/favoriteCenter")

    public Map<String, Object> favouriteTickets(@RequestBody Map<String, String> remap){
        Map<String, Object> res_map = new HashMap<>();
        ArrayList<FavouriteRecord> res = (ArrayList<FavouriteRecord>) favouriteService.searchFavouriteRecordsByUser(remap.get("user_email"));
        if(res == null || res.size() == 0){
            res_map.put("res", false);
            res_map.put("message", "当前没有任何收藏记录");
        }
        else{
            res_map.put("res", true);
            res_map.put("message", "查询收藏记录成功");
            res_map.put("res_list", res);
        }
        return res_map;
    }
}
